<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="/static/js/common/jquery.js"></script>
    <title id="title" hidden>支付宝提现</title>
    <script src="/static/js/putForward/common.js"></script>
    <script src="/static/js/util.js"></script>
    <script src="/static/js/init.js"></script>
    <script src="/static/js/common/flexible.js"></script>
    <link rel="stylesheet" href="/static/css/putForward/common.css">
    <link rel="stylesheet" href="/static/css/putForward/zfbforward.css">
    <style>
        html,body{-webkit-text-size-adjust: 100%;-webkit-tap-highlight-color: rgba(0, 0, 0, 0);}
    </style>
</head>
<body>
<script src="/static/js/Monitor.js"></script>
    <div class="zfbforward">
        <div class="zfb-total">
            <div class="zfb-all">
                <p>收益花粉</p>
                <h2 id="total">--</h2>
            </div>
            <div class="zfb-ok">
                <p>兑换(元)</p>
                <h2 id="putFor">--</h2>
            </div>
        </div>
        <div class="zfb-sum">
            <b>金额</b>
            <input id="money" type="text" placeholder="请输入提现金额（单位:元）">
            <span id="dismiss" class="hide">×</span>
        </div>
        <div class="zfb-add add1">
            <b></b>
            <h3>请添加账户</h3>
            <span></span>
        </div>
        <p class="rule"><span>提现规则说明</span></p>
        <div class="apply" id="apply">申请提现</div>
    </div>
    <div class="message hide" id="message"><span></span></div>
    <script>
        $(function () {
            initUser();
            // 刷新资金账号信息
            refreshCapitalAccount();
            if(!(userobj.accessId && userobj.accessToken)){
                $(".zfbforward").hide()
                $("#title").hide()
                return
            }
            $("#total").html(userobj.gainsBal);
            $("#putFor").html(userobj.gains);
            if(userobj.accountName &&userobj.accountNo){
                $(".add1").removeClass("hide");
                $(".add1>h3").html(userobj.accountName + "(" + userobj.accountNo + ")");
            }
            $(".add1").click(function () {
                window.location.href=base_url+"/putForward/zfbaccount.html";
            })
            //输入金额
            $("#money").on("input",function () {
                var money=$(this).val();
                if(money){
                    $("#dismiss").removeClass("hide");
                    $("#apply").addClass("a-color");
                }else if(money==""){
                    $("#dismiss").addClass("hide");
                    $("#apply").removeClass("a-color");
                }
            });
            //提现规则说明
            $(".rule").click(function () {
                window.location.href=base_url+"/putForward/rule.html";
            });
            //清空输入的金额
            $("#dismiss").click(function () {
                $("#money").val("");
                $(this).addClass("hide");
                $(".apply").removeClass("a-color");
            });

            // 提现申请
            $("#apply").click(function () {
                var price=parseFloat($("#money").val());
                if(isNaN(price)){
                    $("#message span").html("请输入数字");
                    $("#message").removeClass("hide");
                    setTimeout(function () {
                        $("#message").addClass("hide");
                    },2000);
                }else{
                    if(price<30){
                        $("#message span").html("提现金额不低于30");
                        $("#message").removeClass("hide");
                        setTimeout(function () {
                            $("#message").addClass("hide");
                        },2000);
                    }else if(30 <= price && price<=userobj.gains){
                        //提现接口
                        $.ajax({
                            url:genUrl("/wallet/withdraw"),
                            type: 'POST',
                            // contentType:"application/static/json",
                            // dataType:'json',
                            async:false,
                            headers:{
                                "x-access-id": userobj.accessId,
                                "x-access-token": userobj.accessToken,
                                "x-ua": ua
                            },
                            data:{
                                "price":parseFloat(price)
                            },
                            success: function (res) {
                                if(res.code==0){
                                    var withdraw={
                                        accountNo:res.data.accountNo,
                                        price:res.data.price,
                                        realPrice:res.data.realPrice,
                                        serviceCharge:res.data.serviceCharge
                                    }
                                    userobj.withdraw =withdraw;
                                    updateUser(userobj);
                                    window.location.href=base_url+"/putForward/putSuccess.html";
                                }else{
                                    $("#message span").html(res.message);
                                    $("#message").removeClass("hide");
                                    setTimeout(function () {
                                        $("#message").addClass("hide");
                                    },2000);
                                }
                            }
                        });
                    }
                    if(price>userobj.gains){
                        $("#message span").html("不可以超过可提现金额");
                        $("#message").removeClass("hide");
                        setTimeout(function () {
                            $("#message").addClass("hide");
                        },2000);
                    }
                    if(price<userobj.gains && price>5000){
                        $("#message span").html("单日提现不可以超过5000");
                        $("#message").removeClass("hide");
                        setTimeout(function () {
                            $("#message").addClass("hide");
                        },2000);
                    }
                }
            });
        });

    </script>
</body>
</html>